package com.briup.jz.web.controller;

import java.util.List;

import javax.validation.constraints.NotNull;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.jz.bean.BaseConfig;
import com.briup.jz.service.IConfigService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@RestController
@Validated
@RequestMapping("/config")
@Api(description = "系统配置表分类相关接口")
public class ConfigController {
	
	@Autowired
    private IConfigService baseconfigService;

	@ApiOperation(value="查询所有配置信息")
    @GetMapping("findAll")
	public Message query(String name){
        List<BaseConfig> list = baseconfigService.query(name);
        return MessageUtil.success(list);
    }
	

    @ApiOperation(value = "通过id删除")
    @GetMapping("deleteById")
    @ApiImplicitParams({
        @ApiImplicitParam(name="id",value = "主键",paramType = "query", required=true),
    })
    public Message deleteById(@NotNull Long id){
        baseconfigService.deleteById(id);
        return MessageUtil.success("删除成功");
    }
    
	@GetMapping("findByKey")
	@ApiOperation("根据id查询配置信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name="id",value="配置信息id值",dataType="long",paramType="query",required=true),
	})
	public BaseConfig findByKey(Long id){
		return baseconfigService.findByKey(id);
	}

    
    @ApiOperation(value = "SavaOrUpdate")
    @PostMapping("saveOrUpdate")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "序号",paramType = "query",dataType="long"),
            @ApiImplicitParam(name="name",value = "名称",paramType = "query"),
            @ApiImplicitParam(name="val",value = "值",paramType = "query"),
            @ApiImplicitParam(name="introduce",value = "介绍",paramType = "query"),
    })
    public Message saveOrUpdate(BaseConfig baseconfig){
        baseconfigService.saveOrUpdate(baseconfig);
        return MessageUtil.success("更新成功");
    }
}
//test